package com.aiti.lulian.controller.crad;

import cn.hutool.core.util.StrUtil;
import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.*;
import com.aiti.lulian.entity.crad.CardEnterpriseFloor;
import com.aiti.lulian.service.ICardEnterpriseFloorService;
import com.aiti.lulian.vo.CardEnterpriseFloorVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "新版企业楼层控制层")
@RestController
@RequestMapping("/card/floor")
public class CardEnterpriseFloorController extends WebController {

    private final ICardEnterpriseFloorService cardEnterpriseFloorService;

    public CardEnterpriseFloorController(ICardEnterpriseFloorService cardEnterpriseFloorService) {
        this.cardEnterpriseFloorService = cardEnterpriseFloorService;
    }

    @ApiOperation("查询楼层列表")
    @GetMapping("/list")
    public Message getFloorList(CardEnterpriseFloorDto cardEnterpriseFloorDto){
//        String userId = "1";
        String userId = cardEnterpriseFloorDto.getUserId();
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        Integer pageNum = cardEnterpriseFloorDto.getPageNum();
        Integer pageSize = cardEnterpriseFloorDto.getPageSize();
        Page<CardEnterpriseFloor> page = startPage(pageNum, pageSize);
        List<CardEnterpriseFloorVo> list = cardEnterpriseFloorService.getFloorList(cardEnterpriseFloorDto, page);
        return Success(getPageResult(list, pageNum, pageSize, page.getTotal()));
    }

    @ApiOperation("移动楼层")
    @PutMapping("/move")
    public Message moveFloor(@RequestBody CardEnterpriseFloorDto cardEnterpriseFloorDto){
//        String userId = "1";
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.moveFloor(cardEnterpriseFloorDto);
    }

    @ApiOperation("新增图片类和视频类楼层")
    @PostMapping("/addMediaFloor")
    public Message addMediaFloor(@RequestBody CardEnterpriseFloorMediaDto mediaFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        mediaFloor.setUserId(userId);
        return cardEnterpriseFloorService.addMediaFloor(mediaFloor);
    }

    @ApiOperation("新增附件类楼层")
    @PostMapping("/addAttachFloor")
    public Message addAttachFloor(@RequestBody CardEnterpriseFloorAttachDto attachFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        attachFloor.setUserId(userId);
        return cardEnterpriseFloorService.addAttachFloor(attachFloor);
    }

    @ApiOperation("新增或更新链接类楼层")
    @PostMapping("/addOrUpdateLinkFloor")
    public Message addOrUpdateLinkFloor(@RequestBody CardEnterpriseFloorLinkDto linkFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        linkFloor.setUserId(userId);
        return cardEnterpriseFloorService.addOrUpdateLinkFloor(linkFloor);
    }

    @ApiOperation("新增资质类楼层")
    @PostMapping("/addQualificationFloor")
    public Message addQualificationFloor(@RequestBody CardEnterpriseFloorQualificationDto qualificationFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        qualificationFloor.setUserId(userId);
        return cardEnterpriseFloorService.addQualificationFloor(qualificationFloor);
    }

    @ApiOperation("新增图文类或复合类楼层")
    @PostMapping("/addRichTextFloor")
    public Message addRichTextFloor(@RequestBody CardEnterpriseFloorRichTextDto richTextFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        richTextFloor.setUserId(userId);
        return cardEnterpriseFloorService.addRichTextFloor(richTextFloor);
    }

    @ApiOperation("新增图文类或复合类楼层（政府）")
    @PostMapping("/addZfTextFloor")
    public Message addZfTextFloor(@RequestBody CardEnterpriseFloorZfTextDto zfTextFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        zfTextFloor.setUserId(userId);
        return cardEnterpriseFloorService.addZfTextFloor(zfTextFloor);
    }

    @ApiOperation("新增集群类楼层（政府）")
    @PostMapping("/addClusterFloor")
    public Message addClusterFloor(@RequestBody CardEnterpriseFloorClusterDto clusterFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        clusterFloor.setUserId(userId);
        return cardEnterpriseFloorService.addClusterFloor(clusterFloor);
    }

    @ApiOperation("新增附件类楼层（政府）")
    @PostMapping("/addZfFileFloor")
    public Message addZfFileFloor(@RequestBody CardEnterpriseFloorZfFileDto zfFileFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        zfFileFloor.setUserId(userId);
        return cardEnterpriseFloorService.addZfFileFloor(zfFileFloor);
    }

    @ApiOperation("编辑图片类和视频类楼层")
    @PutMapping("/updateMediaFloor")
    public Message updateMediaFloor(@RequestBody CardEnterpriseFloorMediaDto mediaFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        mediaFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateMediaFloor(mediaFloor);
    }

    @ApiOperation("编辑附件类楼层")
    @PutMapping("/updateAttachFloor")
    public Message updateAttachFloor(@RequestBody CardEnterpriseFloorAttachDto attachFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        attachFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateAttachFloor(attachFloor);
    }

    @ApiOperation("编辑资质类楼层")
    @PutMapping("/updateQualificationFloor")
    public Message updateQualificationFloor(@RequestBody CardEnterpriseFloorQualificationDto qualificationFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        qualificationFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateQualificationFloor(qualificationFloor);
    }

    @ApiOperation("编辑图文类或复合类楼层")
    @PutMapping("/updateRichTextFloor")
    public Message updateRichTextFloor(@RequestBody CardEnterpriseFloorRichTextDto richTextFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        richTextFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateRichTextFloor(richTextFloor);
    }

    @ApiOperation("编辑图文类或复合类楼层（政府）")
    @PutMapping("/updateZfTextFloor")
    public Message updateZfTextFloor(@RequestBody CardEnterpriseFloorZfTextDto zfTextFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        zfTextFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateZfTextFloor(zfTextFloor);
    }

    @ApiOperation("编辑集群类楼层（政府）")
    @PutMapping("/updateClusterFloor")
    public Message updateClusterFloor(@RequestBody CardEnterpriseFloorClusterDto clusterFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        clusterFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateClusterFloor(clusterFloor);
    }

    @ApiOperation("编辑附件类楼层（政府）")
    @PutMapping("/updateZfFileFloor")
    public Message updateZfFileFloor(@RequestBody CardEnterpriseFloorZfFileDto zfFileFloor){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        zfFileFloor.setUserId(userId);
        return cardEnterpriseFloorService.updateZfFileFloor(zfFileFloor);
    }

    @ApiOperation("查询图片类和视频类楼层详情")
    @GetMapping("/getMediaFloorDetails")
    public Message getMediaFloorDetails(@RequestParam("baseId") String baseId,
                                        @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getMediaFloorDetails(baseId);
    }

    @ApiOperation("查询附件类楼层详情")
    @GetMapping("/getAttachFloorDetails")
    public Message getAttachFloorDetails(@RequestParam("baseId") String baseId,
                                         @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getAttachFloorDetails(baseId);
    }

    @ApiOperation("查询链接类楼层详情")
    @GetMapping("/getLinkFloorDetails")
    public Message getLinkFloorDetails(@RequestParam("baseId") String baseId,
                                       @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getLinkFloorDetails(baseId);
    }

    @ApiOperation("查询资质类楼层详情")
    @GetMapping("/getQualificationFloorDetails")
    public Message getQualificationFloorDetails(@RequestParam("baseId") String baseId,
                                                @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getQualificationFloorDetails(baseId);
    }

    @ApiOperation("查询图文类或复合类楼层详情")
    @GetMapping("/getRichTextFloorDetails")
    public Message getRichTextFloorDetails(@RequestParam("baseId") String baseId,
                                           @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getRichTextFloorDetails(baseId);
    }

    @ApiOperation("查询图文类或复合类楼层详情（政府）")
    @GetMapping("/getZfTextFloorDetails")
    public Message getZfTextFloorDetails(@RequestParam("baseId") String baseId,
                                         @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getZfTextFloorDetails(baseId);
    }

    @ApiOperation("查询集群类楼层详情（政府）")
    @GetMapping("/getClusterFloorDetails")
    public Message getClusterFloorDetails(@RequestParam("baseId") String baseId,
                                          @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getClusterFloorDetails(baseId);
    }

    @ApiOperation("查询附件类楼层详情（政府）")
    @GetMapping("/getZfFileFloorDetails")
    public Message getZfFileFloorDetails(@RequestParam("baseId") String baseId,
                                         @RequestParam(value = "userId", required = false) String userId){
//        String userId = "1";
        if (StrUtil.isBlank(userId)) {
            userId = findUserId();
        }
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.getZfFileFloorDetails(baseId);
    }

    @ApiOperation("删除楼层")
    @DeleteMapping("/removeFloor")
    public Message removeFloor(@RequestParam("enterpriseId") String enterpriseId,
                               @RequestParam("baseId") String baseId,
                               @RequestParam("type") String type,
                               @RequestParam("sort") Integer sort){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        return cardEnterpriseFloorService.removeFloor(enterpriseId, baseId, type, sort);
    }

    @ApiOperation("编辑楼层")
    @PutMapping("/updateFloor")
    public Message updateFloor(@RequestBody CardEnterpriseFloorDto floorDto){
        String userId = findUserId();
        if (StrUtil.isBlank(userId)) {
            return Fail("请先登录");
        }
        floorDto.setUserId(userId);
        return cardEnterpriseFloorService.updateFloor(floorDto);
    }
}